package day3;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

	public void test1() {
		// int score;
		// int[] scoreArray;
		int[] scores = { 0, 0, 1, 2, 3, 5, 4, 5, 2, 8, 7, 6, 9, 5, 4, 8, 3, 1, 0, 2, 4, 8, 7, 9, 5, 2, 1, 2, 3, 9 };
		int[] counts = new int[10];
		// counts[0]存放0出现次数
		// counts[1]存放1出现次数
		for (int i = 0; i < scores.length; i++) {
			switch (scores[i]) {
			case 0:
				counts[0]++;
				break;
			case 1:
				counts[1]++;
				break;

			default:
				break;
			}
		}
		for (int i = 0; i < counts.length; i++) {
			System.out.println(counts[i]);
		}
	}
	
	
	public void test2() {
		int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int time0 = 0;
		int time1 = 0;
		int time2 = 0;
		int time3 = 0;
		int time4 = 0;
		int time5 = 0;
		int time6 = 0;
		int time7 = 0;
		int time8 = 0;
		int time9 = 0;
		for (int i = 0; i < scores.length; i++) {
			if(scores[i] == 0) {
				time0++;
			}
			if(scores[i]==1) {
				time1++;
			}
			if(scores[i]==2) {
				time2++;
			}
			if(scores[i]==3) {
				time3++;
			}
			if(scores[i]==4) {
				time4++;
			}
			if(scores[i]==5) {
				time5++;
			}
			if(scores[i]==6) {
				time6++;
			}
			if(scores[i]==7) {
				time7++;
			}
			if(scores[i]==8) {
				time8++;
			}
			if(scores[i]==9) {
				time9++;
			}
		}
		System.out.println("0出现的次数为" + time0);
		System.out.println("1出现的次数为" + time1);
		System.out.println("2出现的次数为" + time2);
		System.out.println("3出现的次数为" + time3);
		System.out.println("4出现的次数为" + time4);
		System.out.println("5出现的次数为" + time5);
		System.out.println("6出现的次数为" + time6);
		System.out.println("7出现的次数为" + time7);
		System.out.println("8出现的次数为" + time8);
		System.out.println("9出现的次数为" + time9);
	}
	
	@Test
	public void test4() {
		int[] scores={0,0,1,2,3,5,4,5,2,8,7,6,9,5,4,8,3,1,0,2,4,8,7,9,5,2,1,2,3,9};
		int oddCount = 0;
		int evenCount = 0;
		for (int i = 0; i < scores.length; i++) {
			if (scores[i] % 2 == 0) {
				evenCount++;
			} else {
				oddCount++;
			}
		}
		
		System.out.println("奇数个数：" + oddCount);
		System.out.println("偶数个数：" + evenCount);
	}
	
//	3、输入一组学生的成绩，使用数组，然后计算他们的平均值.
	@Test
	public void test5() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量： ");
		int count = scanner.nextInt();
		int[] array = new int[count];
		int sum = 0;
		for (int i = 0; i < array.length; i++) {
			System.out.println("请输入第" + (i + 1) + "个学生的成绩：");
			array[i] = scanner.nextInt();
			sum += array[i];
		}
		
		System.out.println("这" + array.length + "个学生的平均值是：" + sum / array.length);
	}
	
	@Test
	public void test88() {
		// char[] array = ['a' , 'b', 'c', 'b' , 'a'];
		System.out.println("请输入字符换：");
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();// "abcba"
		System.out.println(str);
		// Alt+Shfit+L
		char[] array = str.toCharArray();
		// 初始认为输入的字符串是回文
		boolean isHuiWen = true;
		for (int i = 0; i < array.length; i++) {
			if (array[i] != array[array.length - i - 1]) {
				isHuiWen = false;
				// 只要找到一个不是回文，后面就不用判断，这个字符串就不是回文
				break;
			}
		}
		if (isHuiWen) {
			System.out.println("是回文");
		} else {
			System.out.println("不是回文");
		}
	}
	
	// 17、输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
	@Test
	public void test66() {
		System.out.println("请输入字符换：");
		Scanner scanner = new Scanner(System.in);
		String str = scanner.nextLine();// "abcba"
		System.out.println(str);
		char[] array = str.toCharArray();
		int letterCount = 0;// 统计字母数量
		int numCount = 0;
		int spaceCount = 0;
		int otherCount = 0;
		for (int i = 0; i < array.length; i++) {
			if ((array[i] >= 'a' && array[i] <= 'z') 
					|| (array[i] >= 'A' && array[i] <= 'Z')) {
				letterCount++;
			} else if (array[i] >= '0' && array[i] <= '9') {
				numCount++;
			} else if (array[i] == ' ') {
				spaceCount++;
			} else {
				otherCount++;
			}
		}
		
		System.out.println("英文字母出现的次数: " + letterCount);
		System.out.println("数字出现的次数: " + numCount);
		System.out.println("空格出现的次数: " + spaceCount);
		System.out.println("其他出现的次数: " + otherCount);
		
	}
	
	@Test
	public void test55() {
		double d1 = 0.3;
		double d2 = 0.2;
		System.out.println(d1 - d2);// 0.09999999999999998
		BigDecimal bigDecimal1 = new BigDecimal("0.3");
		BigDecimal bigDecimal2 = new BigDecimal("0.2");
		BigDecimal result = bigDecimal1.subtract(bigDecimal2);
		System.out.println(result);
	}
	
	
}
